//
//  UIColor+MistKit.h
//  MistKit
//
//  Created by ChenJie on 5/30/20.
//

#import <UIKit/UIKit.h>
#import "metamacros.h"

#define MKColor(hex...) MKColorString(hex)
#define MKColorString(hexString...) __mk_colorHexString__(hexString)
#define MKColorNumber(hexNumber...) __mk_colorHexNumber__(hexNumber)
#define MKRGBColor(red, green, blue...) __mk_colorRGB__(red, green, blue)
#define MKRandomColor(...) __mk_colorRandom__(__VA_ARGS__)

/* Color with hexString */
#define __mk_colorHexString__(args...) \
metamacro_if_eq1(metamacro_argcount(args)) \
    (__mk_colorHexString_1p__(args)) \
    (__mk_colorHexString_2p__(args))

#define __mk_colorHexString_1p__(_hexString) \
[UIColor mk_colorWithHex:(_hexString)]

#define __mk_colorHexString_2p__(_hexString, _alpha) \
[UIColor mk_colorWithHex:(_hexString) alpha:(_alpha)]

/* Color with hexNumber */
#define __mk_colorHexNumber__(args...) \
metamacro_if_eq1(metamacro_argcount(args)) \
    (__mk_colorWithHexNumber_1p__(args)) \
    (__mk_colorWithHexNumber_2p__(args))

#define __mk_colorWithHexNumber_1p__(_hexNumber) \
[UIColor mk_colorWithHexNumber:(0x##_hexNumber)]

#define __mk_colorWithHexNumber_2p__(_hexNumber, _alpha) \
[UIColor mk_colorWithHexNumber:(0x##_hexNumber) alpha:(_alpha)]

/* Color with rgb */
#define __mk_colorRGB__(args...) \
metamacro_if_eq3(metamacro_argcount(args)) \
    (__mk_colorRGB_3p__(args)) \
    (__mk_colorRGB_4p__(args))

#define __mk_colorRGB_3p__(_red, _green, _blue) \
[UIColor mk_colorWithRed:(_red) green:(_green) blue:(_blue)]

#define __mk_colorRGB_4p__(_red, _green, _blue, _alpha) \
[UIColor mk_colorWithRed:(_red) green:(_green) blue:(_blue) alpha:(_alpha)]

/* Color with random */
#define __mk_colorRandom__(args...) __mk_colorRandom_add_1p__(1, ##args)
#define __mk_colorRandom_add_1p__(args...) \
metamacro_if_eq1(metamacro_argcount(args)) \
    (__mk_colorRandom_0p__()) \
    (__mk_colorRandom_1p__(metamacro_at1(args)))

#define __mk_colorRandom_0p__() [UIColor mk_randomColor]
#define __mk_colorRandom_1p__(_alpha) \
[UIColor mk_randomColorWithAlpha:(_alpha)]


@interface UIColor (MistKit)

+ (instancetype)mk_colorWithHex:(NSString *)hexString;

+ (instancetype)mk_colorWithHex:(NSString *)hexString
                          alpha:(CGFloat)alpha;

+ (instancetype)mk_colorWithHexNumber:(NSUInteger)hexNumber;

+ (instancetype)mk_colorWithHexNumber:(NSUInteger)hexNumber
                                alpha:(CGFloat)alpha;

+ (instancetype)mk_colorWithRed:(NSInteger)red
                          green:(NSInteger)green
                           blue:(NSInteger)blue;

+ (instancetype)mk_colorWithRed:(NSInteger)red
                          green:(NSInteger)green
                           blue:(NSInteger)blue
                          alpha:(CGFloat)alpha;

+ (instancetype)mk_randomColor;

+ (instancetype)mk_randomColorWithAlpha:(CGFloat)alpha;

@end

